package GOrden.mobile;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class VisitaFallida {

	private URL Url;
	private String parametros;

	public VisitaFallida(String url, String parametros) {
		this.parametros = parametros;
		try {
			this.Url = new URL(url);
		} catch (MalformedURLException e) {
			throw new RuntimeException(e);
		}
	}

	public String Send(String orden) {
		String result = "";
		HttpURLConnection urlConnection = null;

		try {
			urlConnection = (HttpURLConnection) Url.openConnection();
			urlConnection.setDoOutput(true);
			//urlConnection.setRequestProperty("Accept-Charset", "utf-8");
			//urlConnection.setRequestProperty("Content-Type",
			//		"application/x-www-form-urlencoded;charset=utf-8");

			OutputStream out = new BufferedOutputStream(
					urlConnection.getOutputStream());
			out.write(parametros.getBytes());
			out.flush();

			InputStream in = new BufferedInputStream(
					urlConnection.getInputStream());

			BufferedReader reader = new BufferedReader(new InputStreamReader(
					in, "utf-8"));
			StringBuilder sb = new StringBuilder();
			String line = null;
			while ((line = reader.readLine()) != null) {
				sb.append(line);
			}
			in.close();
			result = sb.toString();
			System.out.println(result);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

		} finally {
			if (urlConnection != null) {
				urlConnection.disconnect();
			}
		}
		return result;
	}

}